package package_principal;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class CasierBox extends JPanel {

	private JButton[] tab_button = new JButton[20];
	private Casier[] tab_casier = new Casier[20];
	
	public CasierBox()
	{
		// Casier define
		setBorder(new LineBorder(new Color(0, 0, 0)));
		
		// Define casier panel
		setLayout(new GridLayout(5, 10, 5, 5));
		
		// Define Casier buttons
		for (int i=0; i<20;i++)
		{
			if (tab_casier[i] == null)
			{
				tab_casier[i] = new Casier(i);
			}
			
			// Button name
			tab_button[i] = new JButton(Integer.toString(tab_casier[i].getIDCasier() ));
			tab_button[i].setBackground(Color.WHITE);
			/* Casier Action Listener */
			tab_button[i].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// TODO Auto-generated method stub
					JButton j = (JButton)arg0.getSource();
					//Button ID
					int c = Integer.parseInt(j.getText());
					if (tab_casier[c].getEtatCasier() == Casier.EtatCasier.VIDE)
					{
						//Ajout new rfid colis
						tab_casier[c].DepotCasier("plop");
						j.setBackground(Color.GRAY);
					}
					else
					{
						tab_casier[c].RetraitCasier();
						j.setBackground(Color.WHITE);
					}
					
				}
			});
			
			add(tab_button[i]);
		}
	}
}
